package org.fall.view.controller;

import org.fall.view.model.ResultEntity;
import org.fall.view.model.dto.NewspaperSubmitDTO;
import org.fall.view.model.po.LeaderInfoPO;
import org.fall.view.model.vo.DailyNewspaperVO;
import org.fall.view.service.MemberUserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author sprogFall
 * @since 2021/4/12 16:26
 */
@Controller
@RequestMapping("/member/work/")
public class MemberWorkController {

    @Resource
    private MemberUserService memberUserService;

    /**
     * 跳转日报填写页面
     * @param modelMap modelMap
     * @return 跳转链接
     */
    @GetMapping("newspaper/page")
    public String toNewspaperPage(ModelMap modelMap, HttpSession session) {
        Integer loginId = (Integer) session.getAttribute("loginId");
        List<LeaderInfoPO> leaderList = memberUserService.getLeaderList(loginId);
        modelMap.put("leaderList", leaderList);
        return "pages/work/daily";
    }

    /**
     * 日报提交接口
     * @param dto 提交日报内容
     * @param session session 用于获取作者信息
     * @return 提交结果
     */
    @PostMapping("newspaper/submit")
    @ResponseBody
    public ResultEntity submitPaper(@RequestBody NewspaperSubmitDTO dto, HttpSession session) {
        Integer loginId = (Integer) session.getAttribute("loginId");
        return memberUserService.submitPaper(dto, loginId);
    }

    /**
     * 查询登录用户自己写的日报
     * @param modelMap modelMap
     * @param session session
     * @return 查询结果
     */
    @GetMapping("newspaper/mine")
    public String getMyNewspaper(ModelMap modelMap, HttpSession session) {
        Integer loginId = (Integer) session.getAttribute("loginId");
        List<DailyNewspaperVO> myNewspaperList = memberUserService.getMyNewspaper(loginId);
        modelMap.put("list", myNewspaperList);
        return "pages/work/show";
    }

    /**
     * 查询抄送给当前登录用户的日报
     * @param modelMap modelMap
     * @param session session
     * @return 查询结果
     */
    @GetMapping("/newspaper/leader")
    public String getLeaderNewspaper(ModelMap modelMap, HttpSession session) {
        Integer loginId = (Integer) session.getAttribute("loginId");
        List<DailyNewspaperVO> myNewspaperList = memberUserService.getLeaderNewspaper(loginId);
        modelMap.put("list", myNewspaperList);
        return "pages/work/show";
    }
}
